package api

import (
	"gitee.com/DengAnbang/Wefore/src/bean"
	"gitee.com/DengAnbang/Wefore/src/dbops"
	"gitee.com/DengAnbang/Wefore/src/fun"
	"gitee.com/DengAnbang/goutils/httpUtils"
	"net/http"
)

/**
* showdoc
* @catalog 接口文档/项目树
* @title 创建节点
* @description 创建节点的接口
* @method socket type=501
* @url /pc/project/treeNode/create
* @param userId 必选 string 创建人的id
* @param nodeName 必选 string 节点名
* @param nodeParentId 选填 string 父节点ID(不填就是新树)
* @return {"code":0,"type":0,"message":"","debug_message":"","data":ProjectTreeBean}
* @return_param node_id string 节点id
* @return_param node_name string 节点名称
* @return_param node_parent_id string 节点父id
* @return_param depth string 树的深度
* @remark nodeParentId不填就是新树
* @number 1
 */
func ProjectTreeNodeCreateHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	nodeName := httpUtils.GetValueFormRequest(r, "nodeName")
	nodeParentId := httpUtils.GetValueFormRequest(r, "nodeParentId")
	node, err := dbops.ProjectTreeNodeCreate(userId, nodeName, nodeParentId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(node)
}
func ProjectTreeNodeCreateSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	nodeName := fun.GetString(parameters, "nodeName")
	nodeParentId := fun.GetString(parameters, "nodeParentId")
	node, err := dbops.ProjectTreeNodeCreate(userId, nodeName, nodeParentId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(node)
}

/**
* showdoc
* @catalog 接口文档/项目树
* @title 申请创建工点
* @description 申请创建工点的接口
* @method socket type=512
* @url /pc/project/treeNode/create/applyFor
* @param userId 必选 string 申请人的id
* @param userName 必选 string 申请人的名字
* @param askUserId 必选 string 节点ID
* @param nodeName 必选 string 节点名
* @param nodeParentName 必选 string 父节点名
* @param nodeParentId 选填 string 父节点ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":ProjectTreeBean}
* @number 1
 */
func ProjectTreeNodeApplyForCreateHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	userName := httpUtils.GetValueFormRequest(r, "userName")
	askUserId := httpUtils.GetValueFormRequest(r, "askUserId")
	nodeName := httpUtils.GetValueFormRequest(r, "nodeName")
	nodeParentId := httpUtils.GetValueFormRequest(r, "nodeParentId")
	nodeParentName := httpUtils.GetValueFormRequest(r, "nodeParentName")
	err := dbops.ProjectTreeNodeApplyForCreate(userId, userName, askUserId, nodeName, nodeParentId, nodeParentName)
	if err != nil {
		return err
	}

	return bean.NewSucceedMessage("提交成功!")
}
func ProjectTreeNodeApplyForCreateSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	userName := fun.GetString(parameters, "userName")
	askUserId := fun.GetString(parameters, "askUserId")
	nodeName := fun.GetString(parameters, "nodeName")
	nodeParentId := fun.GetString(parameters, "nodeParentId")
	nodeParentName := fun.GetString(parameters, "nodeParentName")
	err := dbops.ProjectTreeNodeApplyForCreate(userId, userName, askUserId, nodeName, nodeParentId, nodeParentName)
	if err != nil {
		return err
	}

	return bean.NewSucceedMessage("提交成功!")
}

/**
* showdoc
* @catalog 接口文档/项目树
* @title 向项目中添加一个部门
* @description 向项目中添加一个部门的接口
* @method socket type=510
* @url /pc/project/treeNode/add/structure
* @param userId 必选 string 创建人的id
* @param projectId 必选 string 项目的id
* @param structureNodeId 必选 组织机构树的ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"添加成功"}
* @number 10
 */
func ProjectTreeNodeAddStructureHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	projectId := httpUtils.GetValueFormRequest(r, "projectId")
	structureNodeId := httpUtils.GetValueFormRequest(r, "structureNodeId")
	err := dbops.ProjectTreeNodeAddStructure(userId, projectId, structureNodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("添加成功")
}
func ProjectTreeNodeAddStructureSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	projectId := fun.GetString(parameters, "projectId")
	structureNodeId := fun.GetString(parameters, "structureNodeId")
	err := dbops.ProjectTreeNodeAddStructure(userId, projectId, structureNodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("添加成功")
}

/**
* showdoc
* @catalog 接口文档/项目树
* @title 删除节点
* @description 删除节点的接口
* @method socket type=502
* @url /pc/project/treeNode/delete
* @param nodeId 必选 nodeId 节点ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"删除成功"}
* @remark
* @number 2
 */
func ProjectTreeNodeDeleteHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	err := dbops.ProjectTreeNodeDelete(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("删除成功")
}
func ProjectTreeNodeDeleteSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	err := dbops.ProjectTreeNodeDelete(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("删除成功")
}

/**
* showdoc
* @catalog 接口文档/项目树
* @title 修改节点和设置负责人
* @description 修改节点的接口(仅仅修改名字)
* @method socket type=503
* @url /pc/project/treeNode/update
* @param nodeId 必选 string 节点ID
* @param nodeName 选填 string 节点的新名字
* @param headUserId 选填 string 负责人的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"修改成功"}
* @remark 修改的时候，必须两个值都传
* @number 3
 */
func ProjectTreeNodeUpdateHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	nodeName := httpUtils.GetValueFormRequest(r, "nodeName")
	headUserId := httpUtils.GetValueFormRequest(r, "headUserId")
	err := dbops.ProjectTreeNodeUpdate(nodeId, nodeName, headUserId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("修改成功")
}
func ProjectTreeNodeUpdateSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	nodeName := fun.GetString(parameters, "nodeName")
	headUserId := fun.GetString(parameters, "headUserId")
	err := dbops.ProjectTreeNodeUpdate(nodeId, nodeName, headUserId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("修改成功")
}

/**
* showdoc
* @catalog 接口文档/项目树
* @title 查询节点(一层)
* @description 查询节点的接口(仅仅查询当前节点的子)
* @method socket type=504
* @url /pc/project/treeNode/select/child
* @param nodeId 必选 nodeId 节点ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]ProjectTreeBean}
* @remark
* @number 4
 */
func ProjectTreeChildNodeSelectHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	beans, err := dbops.ProjectTreeChildNodeSelect(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}
func ProjectTreeChildNodeSelectSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	beans, err := dbops.ProjectTreeChildNodeSelect(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}

/**
* showdoc
* @catalog 接口文档/项目树
* @title 查询项目树所有节点(所有子)
* @description 查询节点的接口(查询当前节点的所有子)
* @method socket type=505
* @url /pc/project/treeNode/select/child/all
* @param nodeId 必选 string 节点ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]ProjectTreeBean}
* @remark
* @number 5
 */
func ProjectTreeChildNodeSelectAllHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	beans, err := dbops.ProjectTreeChildNodeSelectAll(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}
func ProjectTreeChildNodeSelectAllSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	beans, err := dbops.ProjectTreeChildNodeSelectAll(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}

/**
* showdoc
* @catalog 接口文档/项目树
* @title 用户添加到项目树中
* @description 用户添加到项目树中的接口
* @method socket type=506
* @url /pc/project/treeNode/user/add
* @param nodeId 必填 string 项目树节点id
* @param userId 必填 string 用户的id，多个权限用”,”隔开
* @param projectId 必填 string 项目的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"添加成功"}
* @remark 这里添加的时候，如果这个人已经在里面了，则会忽略
* @number 6
 */
func ProjectTreeUserAddHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	userId := httpUtils.GetValueFormRequest(r, "userId")
	projectId := httpUtils.GetValueFormRequest(r, "projectId")
	err := dbops.ProjectTreeUserAdd(nodeId, userId, projectId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("添加成功")
}
func ProjectTreeUserAddSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	userId := fun.GetString(parameters, "userId")
	projectId := fun.GetString(parameters, "projectId")
	err := dbops.ProjectTreeUserAdd(nodeId, userId, projectId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("添加成功")
}

/**
* showdoc
* @catalog 接口文档/项目树
* @title 用户从项目树中删除
* @description 用户从项目树中删除的接口
* @method socket type=507
* @url /pc/project/treeNode/user/delete
* @param nodeId 必填 string 项目树节点id
* @param userId 必填 string 用户的id，多个权限用”,”隔开
* @param projectId 必填 string 项目树的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"删除成功"}
* @remark
* @number 7
 */
func ProjectTreeUserDeleteHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	userId := httpUtils.GetValueFormRequest(r, "userId")
	projectId := httpUtils.GetValueFormRequest(r, "projectId")
	err := dbops.ProjectTreeUserDelete(nodeId, userId, projectId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("删除成功")
}
func ProjectTreeUserDeleteSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	userId := fun.GetString(parameters, "userId")
	projectId := fun.GetString(parameters, "projectId")
	err := dbops.ProjectTreeUserDelete(nodeId, userId, projectId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("删除成功")
}

/**
* showdoc
* @catalog 接口文档/项目树
* @title 查询项目树中某一节点的人员
* @description 查询项目树中某一节点的接口
* @method socket type=508
* @url /pc/project/treeNode/user/select
* @param nodeId 必填 string 项目树中某一节点id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]UserBean}
* @remark 最后修改时间:2018.12.07 10.30
* @number 8
 */
func ProjectTreeUserSelectHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	beans, err := dbops.ProjectTreeUserSelect(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}

func ProjectTreeUserSelectSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	beans, err := dbops.ProjectTreeUserSelect(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}

/**
* showdoc
* @catalog 接口文档/项目树
* @title 查询项目树中所有的人员
* @description 查询项目树中所有的人员的接口
* @method socket type=509
* @url /pc/project/treeNode/user/select/all
* @param projectId 必填 string 项目id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]UserBean}
* @remark 最后修改时间:2018.12.07 10.30
* @number 9
 */
func ProjectTreeUserSelectAllHttp(_ http.ResponseWriter, r *http.Request) error {
	projectId := httpUtils.GetValueFormRequest(r, "projectId")
	beans, err := dbops.ProjectTreeUserSelectAll(projectId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}

func ProjectTreeUserSelectAllSocket(parameters map[string]interface{}) error {
	projectId := fun.GetString(parameters, "projectId")
	beans, err := dbops.ProjectTreeUserSelectAll(projectId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}

/**
* showdoc
* @catalog 接口文档/项目树
* @title 查询人员所在的项目
* @description 查询人员所在的项目
* @method socket type=511
* @url /pc/project/treeNode/user/select/project
* @param userId 必填 string 人员id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]ProjectTreeBean}
* @remark 最后修改时间:2018.12.07 10.30
* @number 11
 */
func ProjectTreeUserSelectProjectHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	beans, err := dbops.ProjectTreeUserSelectProject(userId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}

func ProjectTreeUserSelectProjectSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	beans, err := dbops.ProjectTreeUserSelectProject(userId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}
